home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gtlayout / source / lt_newmenutaglist.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  10KB  |  371 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <dos/dos.h>    /* For AmigaDOS error definitions */
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. /*****************************************************************************/
  23.  
  24. #ifdef DO_MENUS    /* Support code */
  25.  
  26. /****** gtlayout.library/LT_NewMenuTagList ******************************************
  27. *
  28. *   NAME
  29. *    LT_NewMenuTagList -- Allocate and layout menu items (V11)
  30. *
  31. *   SYNOPSIS
  32. *    Menu = LT_NewMenuTagList(Tags)
  33. *     D0                       A0
  34. *
  35. *    struct Menu *LT_NewMenuTagList(struct TagItem *);
  36. *
  37. *    struct Menu *LT_NewMenuTags(...);
  38. *
  39. *   FUNCTION
  40. *    Allocates Menus and MenuItems similar to LT_LayoutMenus().
  41. *
  42. *    As of v18 this routine will validate menu mutual exclusion
  43. *    information.
  44. *
  45. *   INPUTS
  46. *    Tags - Pointer to a list of tagitem values, as found
  47. *        in gtlayout.h
  48. *
  49. *
  50. *    Valid tags include:
  51. *
  52. *    LAMN_Screen (struct Screen *) - Pointer to the Screen
  53. *        the menu is to appear upon. This tag is mandatory,
  54. *        unless the LAMN_LayoutHandle tag is used.
  55. *
  56. *    LAMN_TextAttr (struct TextAttr *) - Pointer to the
  57. *        TextAttr to use for the menu layout. If this tag
  58. *        is omitted the Screen->Font will be used.
  59. *
  60. *    LAMN_Error (LONG *) - Pointer to variable to receive
  61. *        an error in case of failure.
  62. *
  63. *    LAMN_AmigaGlyph (struct Image *) - Pointer to Image to
  64. *        use as the Amiga glyph in menus. Will be ignored if
  65. *        NULL.
  66. *
  67. *        NOTE: Ignored by intuition.library v37 and below.
  68. *
  69. *    LAMN_CheckmarkGlyph (struct Image *) - Pointer to Image to
  70. *        use as the checkmark glyph in menus. Will be ignored
  71. *        if NULL.
  72. *
  73. *    LAMN_LayoutHandle (LayoutHandle *) - Pointer to a valid
  74. *        LayoutHandle as created by LT_CreateHandle. This tag
  75. *        provides all the information the single tags
  76. *        LAMN_Screen..LAMN_CheckmarkGlyph would otherwise
  77. *        need to provide.
  78. *
  79. *    LAMN_TitleText (STRPTR) - Name of new menu to create.
  80. *        You may precede the name with the keyboard shortcut
  81. *        to assign to this menu item as follows:
  82. *
  83. *           A\0Save as...
  84. *
  85. *        This will create a menu item using the shortcut "A"
  86. *        and the title "Save as...".
  87. *
  88. *    LAMN_TitleID (LONG) - Locale ID corresponding to the
  89. *        name of the new menu to create.
  90. *        You may precede the name with the keyboard shortcut
  91. *        to assign to this menu item as follows:
  92. *
  93. *           A\0Save as...
  94. *
  95. *        This will create a menu item using the shortcut "A"
  96. *        and the title "Save as...".
  97. *
  98. *    LAMN_ItemText (STRPTR) - Name of new menu item to create.
  99. *        You may precede the name with the keyboard shortcut
  100. *        to assign to this menu item as follows:
  101. *
  102. *           A\0Save as...
  103. *
  104. *        This will create a menu item using the shortcut "A"
  105. *        and the title "Save as...".
  106. *
  107. *    LAMN_ItemID (LONG) - Locale ID corresponding to the
  108. *        name of the new menu item to create.
  109. *        You may precede the name with the keyboard shortcut
  110. *        to assign to this menu item as follows:
  111. *
  112. *           A\0Save as...
  113. *
  114. *        This will create a menu item using the shortcut "A"
  115. *        and the title "Save as...".
  116. *
  117. *    LAMN_SubText (STRPTR) - Name of new submenu item to create.
  118. *        You may precede the name with the keyboard shortcut
  119. *        to assign to this menu item as follows:
  120. *
  121. *           A\0Save as...
  122. *
  123. *        This will create a menu item using the shortcut "A"
  124. *        and the title "Save as...".
  125. *
  126. *    LAMN_SubID (LONG) - Locale ID corresponding to the
  127. *        name of the new submenu item to create.
  128. *        You may precede the name with the keyboard shortcut
  129. *        to assign to this menu item as follows:
  130. *
  131. *           A\0Save as...
  132. *
  133. *        This will create a menu item using the shortcut "A"
  134. *        and the title "Save as...".
  135. *
  136. *    LAMN_KeyText (STRPTR) - Pointer to the string whose first
  137. *        character will be used as the keyboard shortcut for
  138. *        this menu/submenu item.
  139. *
  140. *    LAMN_KeyID (LONG) - Locale ID corresponding to the string whose
  141. *        first character will be used as the keyboard shortcut for
  142. *        this menu/submenu item.
  143. *
  144. *    LAMN_CommandText (STRPTR) - Pointer to the string which
  145. *        will be used as the keyboard shortcut for this
  146. *        menu/submenu item.
  147. *
  148. *    LAMN_CommandID (LONG) - Locale ID corresponding to the string
  149. *        which will be used as the keyboard shortcut for
  150. *        this menu/submenu item.
  151. *
  152. *    LAMN_MutualExclude (ULONG) - Mutual exclusion information for
  153. *        this menu/submenu item.
  154. *
  155. *    LAMN_UserData (APTR) - User data information for this
  156. *        menu/menu item/submenu item.
  157. *
  158. *    LAMN_Disabled (BOOL) - Controls whether this
  159. *        menu/menu item/submenu item should be disabled.
  160. *
  161. *    LAMN_CheckIt (BOOL) - Controls whether this menu/submenu item
  162. *        should be prepared to hold a checkmark.
  163. *
  164. *            NOTE: This does not set the checkmark, use LAMN_Checked
  165. *                for this purpose.
  166. *
  167. *    LAMN_Checked (BOOL) - Controls whether this menu/submenu item
  168. *        should be marked with a checkmark. This tag implies
  169. *        "LAMN_CheckIt,TRUE".
  170. *
  171. *    LAMN_Toggle (BOOL) - Controls whether this menu/submenu item
  172. *        should be prepared to hold a checkmark the user is to
  173. *        toggle on demand. This tag implies "LAMN_CheckIt,TRUE".
  174. *
  175. *            NOTE: this does not set the checkmark, use LAMN_Checked
  176. *                for this purpose.
  177. *
  178. *    LAMN_Code (UWORD) - Raw key code to associate with this
  179. *        menu/submenu item. To find out if a rawkey event
  180. *        corresponds to this menu item use LT_FindMenuCommand.
  181. *
  182. *    LAMN_Qualifier (ULONG) - Key qualifier to associate
  183. *        with this menu/submenu item.
  184. *
  185. *            NOTE: the comparison does not distinguish between
  186. *                the left and right shift/caps/alt qualifier keys.
  187. *
  188. *    LAMN_ID (ULONG) - Unique ID to associate with this
  189. *        menu/menu item/submenu item. You can use this
  190. *        later to look up data using LT_GetMenuItem, etc.
  191. *
  192. *    LAMN_ExtraSpace (UWORD) - Number of pixels to put between
  193. *        neighbouring menu titles. (V18)
  194. *        Default: 0 pixels.
  195. *
  196. *   RESULT
  197. *    Menu - Pointer to Menu structure, ready to pass to
  198. *           SetMenuStrip(), NULL on failure.
  199. *
  200. *   EXAMPLE
  201. *    The following tagitem list:
  202. *
  203. *        LAMN_TitleText,     "Project"
  204. *         LAMN_ItemText,     "New",
  205. *          LAMN_KeyText,     "N",
  206. *         LAMN_ItemText,     "Open...",
  207. *          LAMN_KeyText,     "O",
  208. *         LAMN_ItemText,     NM_BARLABEL,
  209. *         LAMN_ItemText,     "Save",
  210. *          LAMN_KeyText,     "S",
  211. *         LAMN_ItemText,     "A\0Save As...",
  212. *         LAMN_ItemText,     NM_BARLABEL,
  213. *         LAMN_ItemText,     "Print...",
  214. *          LAMN_KeyText,     "P",
  215. *         LAMN_ItemText,     NM_BARLABEL,
  216. *         LAMN_ItemText,     "Help...",
  217. *          LAMN_CommandText, "[Help]",
  218. *         LAMN_ItemText,     NM_BARLABEL,
  219. *         LAMN_ItemText,     "Quit...",
  220. *          LAMN_KeyText,     "Q",
  221. *        TAG_DONE
  222. *
  223. *    Will create the following menu:
  224. *
  225. *    +-------+
  226. *    |Project|
  227. *    +-------+------+
  228. *    |New         aN|
  229. *    |Open...     aO|
  230. *    |~~~~~~~~~~~~~~|
  231. *    |Save        aS|
  232. *    |Save As...  aA|
  233. *    |~~~~~~~~~~~~~~|
  234. *    |Print...    aP|
  235. *    |~~~~~~~~~~~~~~|
  236. *    |Help... [Help]|
  237. *    |~~~~~~~~~~~~~~|
  238. *    |Quit...     aQ|
  239. *    +--------------+
  240. *
  241. *   NOTES
  242. *    You may freely add, remove, spindle & mutilate the contents of the
  243. *    menu strip created, just don't trash or disconnect the base menu
  244. *    entry this routine creates as all menu memory tracking data is
  245. *    connected to it.
  246. *
  247. *   SEE ALSO
  248. *    gtlayout.library/LT_DisposeMenu
  249. *    gtlayout.library/LT_FindCommandItem
  250. *    gtlayout.library/LT_GetMenuItem
  251. *    gtlayout.library/LT_LayoutMenuA
  252. *    gtlayout.library/LT_MenuControlTagList
  253. *    gtlayout.library/LT_NewMenuTemplate
  254. *    intuition.library/SetMenuStrip
  255. *
  256. ******************************************************************************
  257. *
  258. */
  259.  
  260. struct Menu * LIBENT
  261. LT_NewMenuTagList(REG(a0) struct TagItem *TagList)
  262. {
  263.     RootMenu        *Root;
  264.     struct Image    *AmigaGlyph    = NULL,
  265.                     *CheckGlyph = NULL;
  266.     LONG            *ErrorPtr = NULL,
  267.                      Error;
  268.     struct Screen    *Screen = NULL;
  269.     struct TextAttr    *TextAttr = NULL;
  270.     struct TagItem    *List,
  271.                     *Entry;
  272.     LayoutHandle    *Handle = NULL;
  273.     struct Hook        *LocaleHook = NULL;
  274.     LONG             ExtraSpace = 0;
  275.  
  276.     List = TagList;
  277.  
  278.     while(Entry = NextTagItem(&List))
  279.     {
  280.         switch(Entry->ti_Tag)
  281.         {
  282.             case LAMN_AmigaGlyph:
  283.  
  284.                 AmigaGlyph = (struct Image *)Entry->ti_Data;
  285.                 break;
  286.  
  287.             case LAMN_CheckmarkGlyph:
  288.  
  289.                 CheckGlyph = (struct Image *)Entry->ti_Data;
  290.                 break;
  291.  
  292.             case LAMN_Error:
  293.  
  294.                 ErrorPtr = (LONG *)Entry->ti_Data;
  295.                 break;
  296.  
  297.             case LAMN_Screen:
  298.  
  299.                 Screen = (struct Screen *)Entry->ti_Data;
  300.                 break;
  301.  
  302.             case LAMN_TextAttr:
  303.  
  304.                 TextAttr = (struct TextAttr *)Entry->ti_Data;
  305.                 break;
  306.  
  307.             case LAMN_Handle:
  308.  
  309.                 Handle        = (LayoutHandle *)Entry->ti_Data;
  310.                 Screen        = Handle->Screen;
  311.                 TextAttr    = Handle->InitialTextAttr;
  312.                 AmigaGlyph    = Handle->AmigaGlyph;
  313.                 CheckGlyph    = Handle->CheckGlyph;
  314.                 break;
  315.  
  316.             case LAMN_ExtraSpace:
  317.  
  318.                 ExtraSpace = Entry->ti_Data;
  319.                 break;
  320.  
  321.             case LH_LocaleHook:
  322.  
  323.                 LocaleHook = (struct Hook *)Entry->ti_Data;
  324.                 break;
  325.         }
  326.     }
  327.  
  328.     if(Handle)
  329.         LocaleHook = Handle->LocaleHook;
  330.  
  331.     if(ErrorPtr)
  332.         *ErrorPtr = 0;
  333.  
  334.     if(Root = LTP_NewMenu(Screen,TextAttr,AmigaGlyph,CheckGlyph,&Error))
  335.     {
  336.         Root->Handle        = Handle;
  337.         Root->LocaleHook    = LocaleHook;
  338.  
  339.             // Create the menu
  340.  
  341.         if(LTP_CreateMenuTagList(Root,&Error,TagList))
  342.         {
  343.                 // Do the layout
  344.  
  345.             if(LTP_LayoutMenu(Root,0,ExtraSpace))
  346.                 return(&Root->Menu);
  347.             else
  348.                 Error = ERROR_DISK_FULL;
  349.         }
  350.  
  351.         LT_DisposeMenu(&Root->Menu);
  352.     }
  353.  
  354.     if(ErrorPtr)
  355.         *ErrorPtr = Error;
  356.  
  357.     return(NULL);
  358. }
  359.  
  360.  
  361. /*****************************************************************************/
  362.  
  363.  
  364. struct Menu *
  365. LT_NewMenuTags(Tag FirstTag,...)
  366. {
  367.     return(LT_NewMenuTagList((struct TagItem *)&FirstTag));
  368. }
  369.  
  370. #endif    /* DO_MENUS */
  371.